<?php
namespace Home\Model;
use Think\Model\RelationModel;
class QuestionSetModel extends RelationModel{
    //关联
    protected $_link = array(
        //用于检测是试卷是否拥有题目的!!因为只需要知道有木有!所有就查一个数据然后统计一下数量就可以了
        "checkQuestion"=>array(
            "mapping_type"=>3,
            "class_name"=>"question",
            "mapping_name"=>"checkQuestion",
            "foreign_key"=>"qus_id",
            "parent_key"=>"qus_id",
            "mapping_fields"=>"qus_id",         //只取出一个数据
        ),
        //用于删除题目的(其实是获取要删除题目的id)
        "deleteQuestion"=>array(
            "mapping_type"=>3,
            "class_name"=>"question",
            "mapping_name"=>"deleteQuestion",
            "foreign_key"=>"qus_id",
            "parent_key"=>"qus_id",
            "mapping_fields"=>"qus_id,que_id",         //只取出一个数据
        ),
        //用于删除结果表的联级删除
        "deleteResult"=>array(
            "mapping_type"=>3,
            "class_name"=>"student_result",
            "mapping_name"=>"deleteResult",
            "foreign_key"=>"qus_id",
            "parent_key"=>"qus_id",
            "mapping_fields"=>"qus_id",         //只取出一个数据
        ),
        //导入试卷
        "importQuiz"=>array(
            "mapping_type"=>3,
            "class_name"=>"question",
            "mapping_name"=>"importQuiz",
            "foreign_key"=>"qus_id",
            "parent_key"=>"qus_id",
            "mapping_fields"=>"que_type,que_content,que_num,que_item1,que_item2,que_item3,que_item4,que_item5,que_item6,que_item7,que_item8,que_answer"
        )
    );
    //自动验证
    protected $_validate = array(
        //新增(导入也用到)试卷的时候使用1
        array("qus_name","require","试卷名称不能为空!",1,"regex",3),
        array("class_cla_id","number","班级id必须是正整数!",1,"regex",1),
        array("qus_remark","require","试卷简介必须有的!",1,"regex",3),
    );

    //自动填充
    protected $_auto = array(
        //新增试卷的时候自动填充
        array("qus_create_time","getTime",1,"callback"),    //自动填充时间是多少!
        array("qus_status",0,1),        //默认是未使用的!
    );

    protected function getTime(){
        return date("Y-m-d h:i:s",time());
    }
}